package site.guns.domain;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;

import com.n1global.acc.json.CouchDbDocument;
import com.n1global.acc.json.CouchDbDocumentAttachment;
import com.ning.http.util.Base64;

public class GunInfo extends CouchDbDocument {
    private String name;

    private String description;

    private String shopLink;

    private int realisticScore;

    private int accuracyScore;

    private int powerScore;

    private boolean weaverRail;

    private Ammunition ammunition;

    private int price;

    private String links;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getShopLink() {
        return shopLink;
    }

    public void setShopLink(String shopLink) {
        this.shopLink = shopLink;
    }

    public int getRealisticScore() {
        return realisticScore;
    }

    public void setRealisticScore(int realisticScore) {
        this.realisticScore = realisticScore;
    }

    public int getAccuracyScore() {
        return accuracyScore;
    }

    public void setAccuracyScore(int accuracyScore) {
        this.accuracyScore = accuracyScore;
    }

    public int getPowerScore() {
        return powerScore;
    }

    public void setPowerScore(int powerScore) {
        this.powerScore = powerScore;
    }

    public boolean isWeaverRail() {
        return weaverRail;
    }

    public void setWeaverRail(boolean weaverRail) {
        this.weaverRail = weaverRail;
    }

    public Ammunition getAmmunition() {
        return ammunition;
    }

    public void setAmmunition(Ammunition ammunition) {
        this.ammunition = ammunition;
    }

    public void setImage(InputStream in) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        Thumbnails.of(in).outputQuality(0.7).size(600, 400).crop(Positions.CENTER).toOutputStream(out);

        addAttachment("avatar", new CouchDbDocumentAttachment("img/jpeg", Base64.encode(out.toByteArray())));
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getLinks() {
        return links;
    }

    public void setLinks(String links) {
        this.links = links;
    }
}
